package com.ethan.auth.extention;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @Description: TODO
 * @Author ethan
 * @CreateDate:2022/3/23 15:01
 * @UpdateDate: 2021/6/17 08:52
 * @Version 1.0
 */
public class SystemToken extends AbstractAuthenticationToken {

    private final Object principal;
    private Object credentials;
    /**
     * Creates a token with the supplied array of authorities.
     *
     * @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
     *                    represented by this authentication object.
     * @param principal
     * @param credentials
     */
    public SystemToken( Object principal, Object credentials) {
        super(null);

        this.principal = principal;
        this.credentials = credentials;
    }

    public SystemToken(Collection<? extends GrantedAuthority> authorities, Object principal, Object credentials) {
        super(authorities);
        super.setAuthenticated(true);
        this.principal = principal;
        this.credentials = credentials;
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

}
